package it.unipd.dei.project.iandroid;
/*
 *  Adapter per l'oggetto Data
 * 
 */
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class DataAdapter extends ArrayAdapter<Data> {
	// we keep track of model objects in a local variable for our convenience
	private ArrayList<Data> items;
	private Context context;

	public DataAdapter(Context context, int textViewResourceId, ArrayList<Data> items) {
		super(context, textViewResourceId, items);
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// performance issue (see Google I/O video in references)
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.data_adapter_layout, null);
		}
		// position contains the index of the array for
		// the associated item so we retrieve the Contact
		Data c = this.items.get(position);
		if (c != null) {
			TextView name = (TextView) v.findViewById(R.id.name);
			name.setText(c.getName());
			name.setTextColor(android.graphics.Color.BLUE);
			TextView info = (TextView) v.findViewById(R.id.info);
			info.setText(c.getInfo());
			if (c.getInfo().equals("Gallery")) {
				info.setTextColor(android.graphics.Color.RED);
				info.setTextSize(18);
				info.setTypeface(null, android.graphics.Typeface.BOLD);
			}
		}
		return v;
	}

}